{{ $categories := .Site.Taxonomies.categories.ByCount }}
{{ $count := or .Site.Params.widget.categories_count 6 }}
{{ $len := len $categories }}

{{ if gt $len 0 }}
<section class="aside-widget widget-categories content-padding-large soft-size--large soft-style--box">
  <h2 class="widget-header">
    <div class="title">
      <span>{{ i18n "categories" }}</span>
    </div>
  </h2>
  <div class="widget-body">
    <ul class="categories-list">
      {{ range first $count $categories }}
        <li>
          <a href="{{ .Page.Permalink }}">{{ .Page.Data.Term }}</a>
          <span>{{ len .Page.Pages }}</span>
        </li>
      {{ end }}
    </ul>
  </div>

  {{ if gt $len $count }}
    {{ $all_page := $.Site.GetPage (printf "/%s" "categories") }}
    <div class="widget-footer">
      <a href="{{ $all_page.Permalink }}" class="more-link">
        {{ i18n "show_all" }}
        <svg class="icon icon-more" width="16" height="16" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
          <path d="M60.928 247.808c-13.824-13.824-36.352-13.824-50.688 0-13.824 13.824-13.824 36.352 0 50.688L224.256 512 10.24 725.504c-13.824 13.824-13.824 36.352 0 50.688 7.168 7.168 15.872 10.24 25.088 10.24s18.432-3.584 25.088-10.24l239.104-239.104c13.824-13.824 13.824-36.352 0-50.688L60.928 247.808zM417.792 247.808c-13.824-13.824-36.352-13.824-50.688 0-13.824 13.824-13.824 36.352 0 50.688l213.504 213.504-213.504 213.504c-13.824 13.824-13.824 36.352 0 50.688 7.168 7.168 15.872 10.24 25.088 10.24s18.432-3.584 25.088-10.24l239.104-239.104c13.824-13.824 13.824-36.352 0-50.688L417.792 247.808zM1013.76 486.912l-239.104-239.104c-13.824-13.824-36.352-13.824-50.688 0-13.824 13.824-13.824 36.352 0 50.688l213.504 213.504-213.504 213.504c-13.824 13.824-13.824 36.352 0 50.688 7.168 7.168 15.872 10.24 25.088 10.24s18.432-3.584 25.088-10.24l239.104-239.104c14.336-13.824 14.336-36.352 0.512-50.176z"></path>
        </svg>
      </a>
    </div>
  {{ end }}
</section>
{{ end }}